import React, { useContext } from 'react';
import RouterContext from '../RouterContext';

export default function Link({ to, children, ...otherProps }) {
  const { history } = useContext(RouterContext);

  const handelClick = (e) => {
    // 清除默认事件
    e.preventDefault();
    history.push(to);
  };
  return (
    <a href={to} onClick={handelClick} {...otherProps}>
      {children}
    </a>
  );
}
